package com.liangzi.service_core.controller;


import com.liangzi.liangzi_common.exception.Assert;
import com.liangzi.liangzi_common.result.R;
import com.liangzi.liangzi_common.result.ResponseEnum;
import com.liangzi.liangzi_common.util.ArgumentEnum;
import com.liangzi.service_core.pojo.bo.SnowflakeManager;
import com.liangzi.service_core.pojo.entity.VisitPatienter;
import com.liangzi.service_core.pojo.entity.VisitRecordCard;
import com.liangzi.service_core.pojo.vo.VisitPatienterVO;
import com.liangzi.service_core.service.VisitPatienterService;
import com.liangzi.service_core.service.VisitRecordCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 档案卡表 前端控制器
 * </p>
 *
 * @author zhj
 * @since 2021-12-13
 */
@Api(description = "档案卡接口")
@RestController
@RequestMapping("/web/visitRecordCard")
public class VisitRecordCardController {


    @Autowired
    private VisitRecordCardService visitRecordCardService;
    @Autowired
    private VisitPatienterService visitPatienterService;
    @Autowired
    private SnowflakeManager snowflakeManager;
//
//    // 对患者进行建档
//    @ApiOperation("对患者进行建档")
//    @PutMapping("/web/insertRecordCard/{patienterId}")
//    public R insertPatienter(
//            HttpServletRequest httpServletRequest,
//            @PathVariable String patienterId
//           ){
//        // 判断是否登录
//        HttpSession session = httpServletRequest.getSession();
//        String currentRdSession = (String) session.getAttribute(ArgumentEnum.SESSION_RD_SESSION.getValue());
//        if (currentRdSession == null){
//            return R.error().code(ResponseEnum.LOGIN_EXPIRE.getCode()).message(ResponseEnum.LOGIN_EXPIRE.getMessage());
//        }
//        String userId = (String) session.getAttribute(ArgumentEnum.SESSION_USER_ID.getValue());
//
//        Long snowflakeID = null;
//        try {
//            snowflakeID = snowflakeManager.nextValue();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        Assert.notNull(snowflakeID, ResponseEnum.SNOW_FAKE_ID_ERROR);
//        VisitRecordCard visitRecordCard = new VisitRecordCard();
//        visitRecordCard.setRecordCardId(snowflakeID.toString());
//        Boolean isSave = visitRecordCardService.save(visitRecordCard);
//        Boolean isUpdate = false;
//        if (isSave){
//            VisitPatienter patienter = visitPatienterService.getById(patienterId);
//            patienter.setRecordCardId(snowflakeID.toString());
//             isUpdate = visitPatienterService.updateById(patienter);
//
//        }
//
//        return isUpdate ? R.ok().message("建档成功") : R.error().message("建档失败");
//
//    }

}

